﻿using System.Collections.Generic;
using NHibernate;
using ZenMoney.Core.Entities;

namespace ZenMoney.Core.Services
{
	public class CommonService : TransactionalService, ICommonService
	{
		public CommonService(ISession session) : base(session) { }

		public virtual IEnumerable<T> GetAll<T>(int page, int pageSize) where T : BaseEntity
		{
			return Session.QueryOver<T>()
				.Skip(page*pageSize)
				.Take(pageSize).List();
		}

		public virtual T GetById<T>(int entityId) where T : BaseEntity
		{
			return Session.Get<T>(entityId);
		}

		public virtual void Save<T>(T entity) where T : BaseEntity
		{			
			Session.Save(entity);
		}

		public virtual void Delete<T>(T entity) where T : BaseEntity
		{
			Session.Delete(entity);
		}
	}
}
